#!/bin/bash

if [ -e ~/file-dir ]
then
	rm -rf ~/file-dir/*
	echo "存在file-dir，已清空！"
else
	mkdir ~/file-dir
	echo "不存在file-dir，已创建！"
fi
if [ -e ~/dir-dir/ ]
then
	rm -rf ~/dir-dir/*
	echo "存在dir-dir，已清空！"
else
	mkdir ~/dir-dir
	echo "不存在dir-dir，已创建！"
fi
echo "--------------------------------"

read -p "请输入一个指定路径的目录 >" dire 
echo "--------------------------------"
echo "打开$dire"
cd $dire
ls
echo "--------------------------------"
arr=(`ls`)
len=${#arr[*]}
a=0
b=0
while [ $len -gt 0 ]
do
	((len--))
	if [ -f ${arr[len]} ]
	then
		((a++))
		cp "${arr[len]}" ~/file-dir
	elif [ -d ${arr[len]} ]
	then
		((b++))
		cp -r "${arr[len]}" ~/dir-dir
	fi
done

echo "file-dir:"
cd ~/file-dir/
ls
echo -e "文件个数为：$a \n"

echo "dir-dir:"
cd ~/dir-dir/
ls
echo "目录个数为：$b"
